<template>

	<div>
		<el-transfer v-model="value" :data="data"
		 :titles="['未授权', '已授权']"
		 :button-texts="['取消授权', '授权']"
		@change="roleChange"
		></el-transfer>
		
	
	</div>
</template>

<script>
	import UserApi from '@/api/UserApi'
	import RoleApi from '@/api/RoleApi';

	export default {
		data() {
			return {
				data: [],
				value: [],

			};
		},
		props: ["Id"],
		created() {
			this.getdata()
		},
		methods: {
			roleChange(item){
				console.log(item);
				UserApi.Impower(this.Id,this.value).then(res=>{
					if (res.code==1) {
						console.log(res);
						this.$message({
							message:"添加成功",
							type:"success"
						})
						// this.$emit('close')
					}			
				})
			},
			
			getdata() {
				RoleApi.getAll().then(res => {
					if (res.code == 1) {
						console.log(res);
						let arr = []
						res.data.forEach(item => {
							console.log(item);
							arr.push({
								key: item.Id,
								label: item.RoleName,
								disabled: false
							})
						})
						this.data=arr
					}
				}).then(()=>{
					UserApi.YseImpower({userid:this.Id}).then(res=>{
						if (res.code==1) {
							console.log(res);
							let vals = [];
							res.data.forEach(item=>{
								vals.push(item.RoleId)
							})
							this.value = vals
						}
					})
				})
			},
			
			},			
		};
	
</script>

<style>
</style>